﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;
using System.Web;

namespace YiMeiJiaService.Assembly
{
    public static class Common
    {
        /// <summary>
        /// 获取枚举的Description
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="enumValue"></param>
        /// <returns></returns>
        public static string GetDescription<T>(T enumValue) where T : Enum
        {
            FieldInfo fieldInfo = typeof(T).GetField(enumValue.ToString());

            if (fieldInfo != null)
            {
                if (Attribute.GetCustomAttribute(fieldInfo, typeof(DescriptionAttribute)) is DescriptionAttribute attribute)
                {
                    return attribute.Description;
                }
            }
            return enumValue.ToString();
        }

        /// <summary>
        /// 获取URL 中的参数
        /// </summary>
        /// <param name="uri"></param>
        /// <param name="key"></param>
        /// <returns></returns>
        public static string GetParams (string uri,string key)
        {
            var queryParams =HttpUtility.ParseQueryString(uri);
            var value = queryParams[key];
            return value;
        }
    }
}
